﻿Public Class FrmPruebas
#Region "Variables"
    Public totalTimeprof, totalTimeamp, totalTimeae As TimeSpan
    Public totalmemprof, totalmemamp, totalmemae As Integer
    Public tamcamprof, tamcamamp, tamcamae As Integer
    Dim tim As Integer
#End Region

#Region "Botones"
    Private Sub generar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles generar.Click
        If IsNumeric(cantCorridas.Text) And IsNumeric(cantPiezas.Text) Then
            If Me.CBprof.Checked Or Me.CBamp.Checked Or Me.CBaestrella.Checked Then
                Dim acumTimeProf, acumTiemAmp, acumTimeAe As ULong
                Dim minTimeProf, minTimeAmp, minTimeAe As ULong
                Dim maxTimeProf, maxTimeAmp, maxTimeAe As ULong
                Dim acumMemProf, acumMemAmp, acumMemAe As Integer
                Dim minMemProf, minMemAmp, minMemAe As Integer
                Dim maxMemProf, maxMemAmp, maxMemAe As Integer
                Dim TimeProf, TimeAmp, TimeAe As TimeSpan
                Dim camminprof As Integer = 0
                Timer2.Interval = 1000
                Timer2.Enabled = True
                acumMemProf = acumMemAmp = acumMemAe = 0
                acumTimeProf = acumTiemAmp = acumTimeAe = 0
                minMemAe = 999999999
                minMemAmp = 999999999
                minMemProf = 999999999
                minTimeAe = 24 * (60 * (60 * 1000))
                minTimeAmp = 24 * (60 * (60 * 1000))
                minTimeProf = 24 * (60 * (60 * 1000))
                maxMemAe = maxMemAmp = maxMemProf = 0
                maxTimeAe = maxTimeAmp = maxTimeProf = 0
                LBTimer.Visible = True
                Label31.Visible = True
                tim = 0
                For i As Integer = 1 To Me.cantCorridas.Text
                    FrmTablero.pruebas(CInt(Me.cantPiezas.Text))
                    If Me.CBprof.Checked Then
                        acumMemProf = acumMemProf + totalmemprof
                        acumTimeProf = acumTimeProf + totalTimeprof.Ticks
                        If Me.CBaestrella.Checked And (tamcamprof = tamcamae) Then
                            camminprof = camminprof + 1
                        End If
                        If totalmemprof < minMemProf Then
                            minMemProf = totalmemprof
                        End If
                        If totalmemprof > maxMemProf Then
                            maxMemProf = totalmemprof
                        End If
                        If totalTimeprof.Ticks < minTimeProf Then
                            minTimeProf = totalTimeprof.Ticks
                        End If
                        If totalTimeprof.Ticks > maxTimeProf Then
                            maxTimeProf = totalTimeprof.Ticks
                        End If
                    End If
                    If Me.CBamp.Checked And Not FrmTablero.terminar Then
                        acumMemAmp = acumMemAmp + totalmemamp
                        acumTiemAmp = acumTiemAmp + totalmemamp
                        If totalmemamp < minMemAmp Then
                            minMemAmp = totalmemamp
                        End If
                        If totalmemamp > maxMemAmp Then
                            maxMemAmp = totalmemamp
                        End If
                        If totalTimeamp.Ticks < minTimeAmp Then
                            minTimeAmp = totalTimeamp.Ticks
                        End If
                        If totalTimeamp.Ticks > maxTimeAmp Then
                            maxTimeAmp = totalTimeamp.Ticks
                        End If
                    End If
                    If Me.CBaestrella.Checked And Not FrmTablero.terminar Then
                        acumMemAe = acumMemAe + totalmemae
                        acumTimeAe = acumTimeAe + totalmemae
                        If totalmemae < minMemAe Then
                            minMemAe = totalmemae
                        End If
                        If totalmemae > maxMemAe Then
                            maxMemAe = totalmemae
                        End If
                        If totalTimeae.Ticks < minTimeAe Then
                            minTimeAe = totalTimeae.Ticks
                        End If
                        If totalTimeae.Ticks > maxTimeAe Then
                            maxTimeAe = totalTimeae.Ticks
                        End If
                    End If
                    If FrmTablero.terminar Then
                        Exit For
                    End If
                Next
                If Not FrmTablero.terminar Then
                    If Me.CBprof.Checked Then
                        LBPromMemProf.Text = CStr(acumMemProf / CInt(Me.cantCorridas.Text))
                        TimeProf = New TimeSpan(totalTimeprof.Ticks \ CULng(Me.cantCorridas.Text))
                        LBPromTimeProf.Text = CStr(TimeProf.Hours) + " : " + CStr(TimeProf.Minutes) + " : " + CStr(TimeProf.Seconds) + " : " + CStr(TimeProf.Milliseconds)
                        If Me.CBaestrella.Checked Then
                            LBCamMinPor.Text = CStr((camminprof * 100) / Me.cantCorridas.Text)
                            LBCamMinPor.Visible = True
                        End If
                        LBMemMaxProf.Text = maxMemProf
                        LBMemMinProf.Text = minMemProf
                        TimeProf = New TimeSpan(maxTimeProf)
                        LBTimeMaxProf.Text = CStr(TimeProf.Hours) + " : " + CStr(TimeProf.Minutes) + " : " + CStr(TimeProf.Seconds) + " : " + CStr(TimeProf.Milliseconds)
                        TimeProf = New TimeSpan(maxTimeProf)
                        LBTimeMinProf.Text = CStr(TimeProf.Hours) + " : " + CStr(TimeProf.Minutes) + " : " + CStr(TimeProf.Seconds) + " : " + CStr(TimeProf.Milliseconds)
                    End If
                    If Me.CBamp.Checked Then
                        LBPromMemAmp.Text = CStr(acumMemAmp / CInt(Me.cantCorridas.Text))
                        TimeAmp = New TimeSpan(totalTimeamp.Ticks \ CULng(Me.cantCorridas.Text))
                        LBPromTimeAmp.Text = CStr(TimeAmp.Hours) + " : " + CStr(TimeAmp.Minutes) + " : " + CStr(TimeAmp.Seconds) + " : " + CStr(TimeProf.Milliseconds)
                        LBMemMaxAmp.Text = maxMemAmp
                        LBMemMinAmp.Text = minMemAmp
                        TimeAmp = New TimeSpan(maxTimeAmp)
                        LBTimeMaxAmp.Text = CStr(TimeAmp.Hours) + " : " + CStr(TimeAmp.Minutes) + " : " + CStr(TimeAmp.Seconds) + " : " + CStr(TimeProf.Milliseconds)
                        TimeAmp = New TimeSpan(maxTimeAmp)
                        LBTimeMinAmp.Text = CStr(TimeAmp.Hours) + " : " + CStr(TimeAmp.Minutes) + " : " + CStr(TimeAmp.Seconds) + " : " + CStr(TimeProf.Milliseconds)
                    End If
                    If Me.CBaestrella.Checked Then
                        LBPromMemAe.Text = CStr(acumMemAe / CInt(Me.cantCorridas.Text))
                        TimeAe = New TimeSpan(totalTimeae.Ticks \ CULng(Me.cantCorridas.Text))
                        LBPromTimeAe.Text = CStr(TimeAe.Hours) + " : " + CStr(TimeAe.Minutes) + " : " + CStr(TimeAe.Seconds) + " : " + CStr(TimeAe.Milliseconds)
                        LBMemMaxAe.Text = maxMemAe
                        LBMemMinAe.Text = minMemAe
                        TimeAe = New TimeSpan(maxTimeAe)
                        LBTimeMaxAe.Text = CStr(TimeAe.Hours) + " : " + CStr(TimeAe.Minutes) + " : " + CStr(TimeAe.Seconds) + " : " + CStr(TimeAe.Milliseconds)
                        TimeAe = New TimeSpan(maxTimeAe)
                        LBTimeMinAe.Text = CStr(TimeAe.Hours) + " : " + CStr(TimeAe.Minutes) + " : " + CStr(TimeAe.Seconds) + " : " + CStr(TimeAe.Milliseconds)
                    End If
                    GroupBox2.Visible = True
                End If
                Timer2.Enabled = False
                LBTimer.Visible = False
                Label31.Visible = False
                LBTimer.Text = "0"
                If FrmTablero.terminar Then
                    MsgBox("El proceso ha sido detenido")
                    FrmTablero.terminar = False
                End If
            End If
        End If

    End Sub

    Private Sub BnCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BnCerrar.Click
        FrmTablero.tableroAjedrez.limpiarTablero()
        Me.Close()
    End Sub
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        tim = tim + 1
        LBTimer.Text = CStr(tim)
        Me.Refresh()
    End Sub
#End Region

    Private Sub BTParar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTParar.Click
        FrmTablero.parar = True
    End Sub
End Class